package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import com.qiniu.util.Json;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return orderService.findPage(queryPageBean);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Map map){
        Result result = null;
        try {
           result= orderService.add(map);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"添加预约失败");
        }
        return result;
    }

    //确认预约
    @RequestMapping("/ConfirmAppointment")
    public Result confirmAppointment(Integer id){
        Result result = null;
        try {
          result= orderService.confirmAppointment(id);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"预约失败");
        }
       return result;
    }

    //取消预约
    @RequestMapping("/cancelReservation")
    public Result cancelReservation(Integer id){
        try {
            orderService.cancelReservation(id);
            return new Result(true,"取消预约成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"取消预约失败");
        }
    }

    @RequestMapping("/batchCancelReservation")
    public Result batchCancelReservation( Integer[] orderIds){
        try {
            orderService.batchCancelReservation(orderIds);
            return new Result(true,"取消预约成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"取消预约失败");
        }
    }
}
